<?php
class streetdao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function getbyid($street_id){
		$this->db->select('*');
		$this->db->from('street');
		$this->db->where('street_id',$street_id);
		$query = $this->db->get();
		$street = $query->row();
		return $street;
	}
	
	public function get_all(){
		$this->db->select('*');
		$this->db->from('street');
		$query = $this->db->get();
		$streets = $query->result();
		return $streets;
	}
	
	public function insert($street_name,$neighborhood_id){
		$data = array(
				'street_name' => $street_name,
				'neighborhood_id' => $neighborhood_id,
		);
		$str = $this->db->insert_string('street', $data);
		$res = $this->db->query($str);
		return $res;
	}
	
	public function del($street_id) {
		if (intval($street_id) > 0) {
			$this->db->where('street_id', $street_id);
			$this->db->delete('street');
			return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
		}
		return false;
	}
	
	function get_by_neighborhood($neighborhood_id){
		$this->db->select('street.*');
		$this->db->from('neighborhood');
		$this->db->join('street', 'neighborhood.neighborhood_id
					 = street.neighborhood_id');
		$this->db->where('street.neighborhood_id',
				$neighborhood_id);
		$query = $this->db->get();
		$result = $query->result();
		return $result;
	}
}
?>